package com.daxia.bumall.web.controller.admin;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.daxia.bumall.common.Logs;
import com.daxia.bumall.common.ProductSellingStatus;
import com.daxia.bumall.common.ProductStatus;
import com.daxia.bumall.common.ProductType;
import com.daxia.bumall.common.UserType;
import com.daxia.bumall.dto.BrandDTO;
import com.daxia.bumall.dto.JsonResultDTO;
import com.daxia.bumall.dto.ProductCategoryDTO;
import com.daxia.bumall.dto.ProductDTO;
import com.daxia.bumall.dto.ProductPropertiesDTO;
import com.daxia.bumall.dto.SpecificationDTO;
import com.daxia.bumall.dto.UserDTO;
import com.daxia.bumall.model.Brand;
import com.daxia.bumall.model.Product;
import com.daxia.bumall.model.ProductProperties;
import com.daxia.bumall.model.Specification;
import com.daxia.bumall.model.User;
import com.daxia.bumall.service.BrandService;
import com.daxia.bumall.service.DesignProductService;
import com.daxia.bumall.service.ProductService;
import com.daxia.bumall.service.SpecificationService;
import com.daxia.bumall.service.UserService;
import com.daxia.bumall.support.Page;
import com.daxia.bumall.util.QiniuUtils;
import com.daxia.bumall.util.SpringSecurityUtils;
import com.daxia.bumall.web.controller.BaseController;

@Controller
@RequestMapping(value = "/admin/product", produces = "text/html;charset=UTF-8")
public class AdminProductController extends BaseController {

	@Autowired
	private ProductService productService;
	@Autowired
	private SpecificationService specificationService;
	@Autowired
	private UserService userService;
	@Autowired
	private BrandService brandService;
	@Autowired
	private DesignProductService designProductService;

	@RequestMapping(value = "/detail")
	public String detail(Map<String, Object> map, Long id) {
		if (id != null) {
			ProductDTO dto = productService.load(id);
			Product model = new Product();
			model.setId(id);
			SpecificationDTO sDto = new SpecificationDTO();
			sDto.setProduct(model);
			// List<SpecificationDTO> list = specificationService.find(sDto,
			// null);
			// dto.setSpecifications(list);
			map.put("n", dto);
		}
		map.put("pts", ProductType.values());
		return "admin/product/product_detail";
	}
	
	@RequestMapping(value = "/review")
	public String review(Map<String, Object> map, Long id) {
		ProductDTO dto = productService.load(id);
		map.put("n", dto);
		return "admin/product/product_review";
	}
	
	@ResponseBody
	@RequestMapping(value = "/doReview")
	public String doReview(Map<String, Object> map, Long id, Integer status, JsonResultDTO resultDTO) {
		ProductDTO dto = productService.load(id);
		dto.setStatus(status);
		productService.updateAllFields(dto);
		return okAndClose(resultDTO);
	}
	
	@ResponseBody
	@RequestMapping(value = "/doSellStatusAll")
	public String doSellStatusAll(Map<String, Object> map, Long[] ids, JsonResultDTO resultDTO) {
		productService.updateSellStatus(ids, ProductSellingStatus.OffSell.getValue());
		return okAndClose(resultDTO);
	}
	@ResponseBody
	@RequestMapping(value = "/updateOnline")
	public String updateOnline(Map<String, Object> map, Long[] ids, JsonResultDTO resultDTO) {
		productService.updateSellStatus(ids, ProductSellingStatus.OnSell.getValue());
		return okAndClose(resultDTO);
	}
	
	@ResponseBody
	@RequestMapping(value = "/doReviewAll")
	public String doReviewAll(Map<String, Object> map, Long[] ids, JsonResultDTO resultDTO) {
		productService.updateStatus(ids, ProductStatus.Passed.getValue());
		return okAndClose(resultDTO);
	}

	@ResponseBody
	@RequestMapping(value = "/save")
	
	public String save(ProductDTO dto, JsonResultDTO resultDTO) throws Exception {
		Date now = new Date();
		// set store
		//
		// dto.setStore(store);
		//dto.setIsRecommend(false);

		dto.setLastUpdateTime(now);
		if (dto.getId() == null) {
			Long brandId = dto.getBrand().getId();
			BrandDTO brandDTO = brandService.load(brandId);
			dto.setUser(brandDTO.getFactoryInfo().getUser());
			dto.setCreateTime(now);
			productService.create(dto);
		} else {
			ProductDTO old = productService.load(dto.getId());
			old.setBrand(dto.getBrand());
			old.setName(dto.getName());
			old.setSubTitle(dto.getSubTitle());
			old.setProductCategory(dto.getProductCategory());
			old.setUnit(dto.getUnit());
			old.setSellingStatus(dto.getSellingStatus());
			old.setHeadImage(dto.getHeadImage());
			old.setImages(dto.getImages());
			old.setDetails(dto.getDetails());
			old.setLastUpdateTime(now);
			old.setIsRecommend(dto.getIsRecommend());
			productService.updateAllFields(old);
		}
		return okAndClose(resultDTO);
	}

	
	@ResponseBody
	@RequestMapping(value = "/delete")
	public String delete(Long[] ids, JsonResultDTO resultDTO) throws IOException {
		productService.deleteByIds(ids);
		return okAndRefresh(resultDTO);
	}

	@RequestMapping(value = "/list")
	public String list(ProductDTO dto, Map<String, Object> map, Page page) {
		User user = (User) SpringSecurityUtils.getCurrentUser();
		if (user.getType() == UserType.Factory.getValue()) {
			dto.setUser(user);
		}
		if (dto.getStatus() != null) {
			dto.setAllStatus(false);
		} else {
			dto.setAllStatus(true);
		}
		dto.setFromAdmin(true);
		List<ProductDTO> dtos = productService.find(dto, page);
		map.put("list", dtos);
		map.put("query", dto);
		map.put("pts", ProductType.values());
		map.put("pss", ProductSellingStatus.values());
		map.put("prss", ProductStatus.values());
		return "admin/product/product_list";
	}
	
	

	@ResponseBody
	@RequestMapping(value = "/datagrid")
	
	public String datagrid(ProductDTO dto, Map<String, Object> map, Page page) throws Exception {
		List<ProductDTO> dtos = productService.find(dto, page);
		JSONArray jsonArray = new JSONArray();
		for (ProductDTO product : dtos) {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("id", product.getId());
			jsonObject.put("store.name", product.getStore().getName());
			jsonObject.put("name", product.getName());
			jsonObject.put("subTitle", product.getSubTitle());
			jsonObject.put("productCategory.name", product.getProductCategory().getName());
			jsonObject.put("unit", product.getUnit());
			jsonObject.put("sellingStatus", product.getSellingStatus());
			jsonObject.put("isRecommend", product.getIsRecommend());
			jsonObject.put("brand.name", product.getBrand().getName());
			jsonObject.put("details", product.getDetails());
			jsonObject.put("createTime", formatDate(product.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
			jsonObject.put("lastUpdateTime", formatDate(product.getLastUpdateTime(), "yyyy-MM-dd HH:mm:ss"));
			jsonObject.put("images", product.getImages());
			jsonArray.add(jsonObject);
		}
		JSONObject json = new JSONObject();
		json.put("total", page.getTotalRecords());
		json.put("rows", jsonArray);
		return json.toJSONString();
	}

	@Transactional
	@ResponseBody
	@RequestMapping("uploadImages")
	public String uploadImages(HttpServletRequest request) throws Exception {
		MultipartHttpServletRequest mhs = (MultipartHttpServletRequest) request;
		List<MultipartFile> mfList = mhs.getFiles("files");
		assertTrue(mfList.size() <= 100, "一次只能上传100张图片");
		for (MultipartFile mf : mfList) {
			String originalFilename = mf.getOriginalFilename();
			String imageUrl = QiniuUtils.upload(mf.getBytes(), originalFilename);
			String factoryCode = originalFilename.split("\\.")[0];
			factoryCode = factoryCode.split("-")[0];
			factoryCode = factoryCode.split("_")[0];
			factoryCode = factoryCode.split("\\(")[0];
			factoryCode = factoryCode.split("（")[0];
			SpecificationDTO query = new SpecificationDTO();
			// query.setFactoryCode(factoryCode);
			query.setOgCode(factoryCode);
			SpecificationDTO s = specificationService.findOne(query);
			if (s != null) {
				if (StringUtils.isBlank(s.getImages())) {
					s.setImages(imageUrl);
				} else {
					s.setImages(s.getImages() + "," + imageUrl);
				}
				specificationService.updateAllFields(s);
				ProductDTO p = productService.load(s.getProduct().getId());
				if (StringUtils.isBlank(p.getHeadImage())) {
					p.setHeadImage(imageUrl);
				}
				if (StringUtils.isBlank(p.getImages())) {
					p.setImages(imageUrl);	
				} else {
					p.setImages(p.getImages() + "," + imageUrl);
				}
				productService.updateAllFields(p);
			}
		}
		return okAndClose(new JsonResultDTO());
	}
	
	@RequestMapping("productUpload")
	public String productUpload(Map<String, Object> map) {
		User user = (User) SpringSecurityUtils.getCurrentUser();
		if (user.getType() ==  UserType.Factory.getValue()) {
			map.put("isFactory", true);
		} else {
			map.put("isFactory", false);
		}
		return "admin/product/product_upload";
	}
	
	@Transactional
	@ResponseBody
	@RequestMapping("uploadFixSpec")
	public String uploadFixSpec(HttpServletRequest request, Long userId) throws Exception {
		userId = StringUtils.isNotBlank(request.getParameter("userId")) ? Long.valueOf(request.getParameter("userId")) : null;
		MultipartHttpServletRequest mhs = (MultipartHttpServletRequest) request;  
        MultipartFile mf = mhs.getFile("file");
		Workbook book = WorkbookFactory.create(mf.getInputStream());

		Sheet sheet = book.getSheetAt(0);
		Iterator<Row> iterable = sheet.rowIterator();
		iterable.next(); // 第一行是header，不要
		while (iterable.hasNext()) {
			Row row = iterable.next();
			String ogCode = row.getCell(7).getStringCellValue().trim();
			
			if (StringUtils.isBlank(ogCode)) {
				continue;
			}
			SpecificationDTO query = new SpecificationDTO();
			
			query.setOgCode(ogCode);
			
			SpecificationDTO s = specificationService.findOne(query);
			if (s == null) {
				continue;
			}
			if (s.getProductProperties() != null) {
				for (ProductProperties pp : s.getProductProperties()) {
					productPropertiesService.deleteById(pp.getId());
				}
			}
			String properties = row.getCell(5).getStringCellValue().trim();
			if (StringUtils.isNotBlank(properties)) {
				// 件数:4件;被面材质:棉;品牌:金太阳;被里材质:棉;床品工艺:绗缝;适用床尺寸:1.5m（5英尺）床 1.8m（6英尺）床;图案: 花卉;款式:床单式 颜色分类:兰色;产品等级:一等品;风格:乡村田园;面料支数:40支;面料密度: 128x68;印花工艺: 活性印花;织造工艺: 其他
				String[] arr = properties.split(";");
				for (String string : arr) {
					String[] keyValues = string.split(":");
					if (keyValues.length == 2) {
						ProductPropertiesDTO pp = new ProductPropertiesDTO();
						pp.setName(keyValues[0]);
						pp.setValue(keyValues[1]);
						//pp.setProduct(p);
						pp.setSpecification(new Specification());
						pp.getSpecification().setId(s.getId());
						productPropertiesService.create(pp);
					}
				}
			}
			
			
		}
	
		return okAndClose(new JsonResultDTO());
	}
	
	@Transactional
	@ResponseBody
	@RequestMapping("uploadFixPrice")
	public String uploadFixPrice(HttpServletRequest request, Long userId) throws Exception {
		userId = StringUtils.isNotBlank(request.getParameter("userId")) ? Long.valueOf(request.getParameter("userId")) : null;
		MultipartHttpServletRequest mhs = (MultipartHttpServletRequest) request;  
        MultipartFile mf = mhs.getFile("file");
		Workbook book = WorkbookFactory.create(mf.getInputStream());

		Sheet sheet = book.getSheetAt(0);
		Iterator<Row> iterable = sheet.rowIterator();
		iterable.next(); // 第一行是header，不要
		while (iterable.hasNext()) {
			Row row = iterable.next();
			if (row.getCell(7) == null) {
				continue;
			}
			String ogCode = row.getCell(7).getStringCellValue().trim();
			
			if (StringUtils.isBlank(ogCode)) {
				continue;
			}
			SpecificationDTO query = new SpecificationDTO();
			
			query.setOgCode(ogCode);
			
			SpecificationDTO s = specificationService.findOne(query);
			if (s == null) {
				continue;
			}
			double sellingPrice = 0;
			try {
				sellingPrice = row.getCell(11).getNumericCellValue();
			} catch (Exception e) {
				sellingPrice = Double.parseDouble(row.getCell(11).getStringCellValue().trim());
			}
			s.setSellingPrice(sellingPrice);
			specificationService.updateAllFields(s);
		}
	
		return okAndClose(new JsonResultDTO());
	}
	
	@Transactional
	@ResponseBody
	@RequestMapping("uploadFixBrand")
	public String uploadFixBrand(HttpServletRequest request, Long userId) throws Exception {
		MultipartHttpServletRequest mhs = (MultipartHttpServletRequest) request;  
        MultipartFile mf = mhs.getFile("file");
		Workbook book = WorkbookFactory.create(mf.getInputStream());

		Sheet sheet = book.getSheetAt(0);
		Iterator<Row> iterable = sheet.rowIterator();
		iterable.next(); // 第一行是header，不要
		while (iterable.hasNext()) {
			Row row = iterable.next();
			String ogCode = row.getCell(7).getStringCellValue().trim();
			
			if (StringUtils.isBlank(ogCode)) {
				continue;
			}
			SpecificationDTO query = new SpecificationDTO();
			
			query.setOgCode(ogCode);
			
			SpecificationDTO s = specificationService.findOne(query);
			if (s == null) {
				continue;
			}
			
			String brand = row.getCell(4).getStringCellValue().trim();
			BrandDTO dbBrand = brandService.findByName(brand);
			if (dbBrand == null) {
				throw new RuntimeException("找不到品牌【" + brand + "】");
			}
			
			ProductDTO p = productService.load(s.getProduct().getId());
			p.setBrand(new Brand());
			p.getBrand().setId(dbBrand.getId());
			productService.updateAllFields(p);
		}
	
		return okAndClose(new JsonResultDTO());
	}
	
	@Transactional
	@ResponseBody
	@RequestMapping("uploadExcel")
	public String uploadExcel(HttpServletRequest request, Long userId) throws Exception {
		MultipartHttpServletRequest mhs = (MultipartHttpServletRequest) request;  
        MultipartFile mf = mhs.getFile("file");
		Workbook book = WorkbookFactory.create(mf.getInputStream());

		Sheet sheet = book.getSheetAt(0);
		// 获取左上角的单元格
		int count = 1;
		Iterator<Row> iterable = sheet.rowIterator();
		iterable.next(); // 第一行是header，不要
		ProductDTO lastProduct = null; // 有时第二行没有产品，是因为用的上一行的产品
		String lastProperties = null;
		String lastFactoryCode = null;
		String lastOgCode = null;
		String lastCategories = null;
		boolean continueLast = false;
		// key: brandid, value seq
		Map<Long, Integer> seqMap = new HashMap<Long, Integer>();
		while (iterable.hasNext()) {
			count ++;
			Logs.COMMON.debug("开始处理第 " + count + "行");
			Row row = iterable.next();
			try {
				for (int i = 0; i <= 16; i++) {
					if (row.getCell(i) != null) {
						row.getCell(i).setCellType(Cell.CELL_TYPE_STRING);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			if ((row.getCell(0) == null || StringUtils.isBlank(row.getCell(0).getStringCellValue().trim())) && lastProduct == null) {
				// 第一行就是空，不处理
				continue;
			}
			String name;
			if (row.getCell(0) == null || StringUtils.isBlank(row.getCell(0).getStringCellValue().trim())) {
				// 继续上一行的产品
				name = lastProduct.getName();
				continueLast = true;
				
			} else {
				// 开始新产品
				continueLast = false;
				lastProduct = null; // 开始新的产品
				name = row.getCell(0).getStringCellValue().trim();
			}
			Logs.COMMON.debug("name: " + name);
			if (StringUtils.isBlank(name)) {
				continue;
			}
			if (row.getCell(7) == null) {
				continue;
				//throw new RuntimeException("达达订货编码不能为空");
			}
			String ogCode = row.getCell(7).getStringCellValue().trim();
			if (StringUtils.isBlank(ogCode)) {
				//throw new RuntimeException("达达订货编码不能为空");
				continue;
			}
			SpecificationDTO oldSpec = specificationService.findByOgCode(ogCode);
			if (oldSpec != null) {
				Logs.COMMON.debug(ogCode + "已经上传过了，不再上传");
				continue;
			}
			
			String subTitle = null;
			String unit = null;
			String brand = null;
			String properties = null;
			String factoryCode = null;
			// 规格编码
			
			brand = row.getCell(4).getStringCellValue().trim();
			if (continueLast) { // 用上一行的
				subTitle = lastProduct.getSubTitle();
	//			properties = lastProperties;
			} else { // 重新读取
				subTitle = row.getCell(1).getStringCellValue().trim();
				unit = row.getCell(3).getStringCellValue().trim();
//				properties = row.getCell(5).getStringCellValue().trim();
			}
			if (row.getCell(5) == null || row.getCell(5).getStringCellValue() == null) {
				continue;
			}
			properties = row.getCell(5).getStringCellValue().trim();
			if (row.getCell(6) == null) {
				continue;
			}
			row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
			factoryCode = row.getCell(6).getStringCellValue().trim();
			if (StringUtils.isBlank(factoryCode)) {
				continue;
			}
			BrandDTO dbBrand = brandService.findByName(brand);
			if (dbBrand == null) {
				throw new RuntimeException("找不到品牌【" + brand + "】");
			}
			
			String specCode = row.getCell(8).getStringCellValue().trim();
			String spec1 = row.getCell(9).getStringCellValue().trim();
			String spec2 = row.getCell(10).getStringCellValue().trim();
			
			double sellingPrice = 0;
			try {
				sellingPrice = row.getCell(11).getNumericCellValue();
			} catch (Exception e) {
				sellingPrice = Double.parseDouble(row.getCell(11).getStringCellValue().trim());
			}

			String stock = null;
			try {
				stock = row.getCell(15).getStringCellValue().trim();
			} catch (Exception e) {
				stock = "" + row.getCell(15).getNumericCellValue();
			}

			String categories = null; 
			if (continueLast) {
				categories = lastCategories;
			} else {
				categories = row.getCell(16).getStringCellValue().trim();
				lastCategories = categories;
			}
			
			
			if (StringUtils.isBlank(categories)) {
				throw new RuntimeException("分类不能为空");
			}
			String[] categoryArr = categories.split(";");
			if (categoryArr.length != 3) {
				throw new RuntimeException("分类【" + categories + "】格式不正确");
			}
			String _name = categoryArr[0];
			ProductCategoryDTO level1 = productCategoryService.findByName(_name);
			if (level1 == null) {
				throw new RuntimeException("分类【" + _name + "】不存在");
			}
			_name = categoryArr[1];
			ProductCategoryDTO level2 = productCategoryService.findByName(_name);
			if (level2 == null) {
				throw new RuntimeException("分类【" + _name + "】不存在");
			}
			_name = categoryArr[2];
			ProductCategoryDTO level3 = productCategoryService.findByName(_name);
			if (level3 == null) {
				throw new RuntimeException("分类【" + _name + "】不存在");
			}
			
			ProductCategoryDTO productCategory = productCategoryService.findOne(categoryArr[0], categoryArr[1], categoryArr[2]);
			if (productCategory == null) {
				throw new RuntimeException("分类【" + categories + "】不存在");
			}
			if (lastProduct == null) {  // 之前没有这产品
				ProductDTO p = new ProductDTO();
				p.setName(name);
				p.setSubTitle(subTitle);
				p.setUnit(unit);
				p.setBrand(new Brand());
				p.getBrand().setId(dbBrand.getId());
				//页面上选择的商品分类
				p.setProductCategory(productCategory);
				//管理员或者工厂
				if (userId == null) {
					userId = SpringSecurityUtils.getCurrentUser().getId(); // 管理员
				}
				User user = new User();
				user.setId(userId);
				p.setUser(user);
				
				Logs.COMMON.debug("开始创建商品，name: " + name);
				Long productId = productService.create(p);
				p = productService.load(productId);
				lastProduct = p;
			}
			
			UserDTO userDto = userService.load(userId);
			if (StringUtils.isBlank(userDto.getSeq())) {
				throw new RuntimeException("该工厂未设置供应商对应码");
			}
			BrandDTO brandDTO = brandService.load(dbBrand.getId());
			if (StringUtils.isBlank(brandDTO.getCode())) {
				throw new RuntimeException("品牌【" + brandDTO.getName() + "】未设置编码");
			}
			
			Integer seq = seqMap.get(dbBrand.getId());
			if (seq == null) {
				SpecificationDTO spDto = new SpecificationDTO();
				spDto.setProduct(new Product());
				spDto.getProduct().setBrand(new Brand());
				spDto.getProduct().getBrand().setId(dbBrand.getId());
				Integer speSeq = specificationService.findSeq(spDto);
				Logs.COMMON.debug("brandid: " + dbBrand.getId() + ", speseq: " + speSeq);
				seq = speSeq + 1;
				seqMap.put(dbBrand.getId(), seq);
			} else {
				seqMap.put(dbBrand.getId(), seq + 1);
			}
			seq = seqMap.get(dbBrand.getId());
			
			if (StringUtils.isBlank(ogCode)) {
				ogCode = "O" + specCode + "Y" + userDto.getSeq() + brandDTO.getCode() + String.format("%03d", seq);
			}
			
			SpecificationDTO s = new SpecificationDTO();
			s.setFactoryCode(factoryCode);
			s.setOgCode(ogCode);
			s.setSpec1(spec1);
			s.setSpec2(spec2);
			s.setSellingPrice(sellingPrice);
			s.setMarketPrice(sellingPrice * 1.1);
			s.setStock(new BigDecimal(stock).intValue());
			s.setSeq(seq);
			s.setProduct(lastProduct);
			
			ProductDTO productDTO = productService.load(s.getProduct().getId());
			s.setProduct(productDTO);
			Long sId = specificationService.create(s);
			s = specificationService.load(sId);
			if (StringUtils.isNotBlank(properties)) {
				// 件数:4件;被面材质:棉;品牌:金太阳;被里材质:棉;床品工艺:绗缝;适用床尺寸:1.5m（5英尺）床 1.8m（6英尺）床;图案: 花卉;款式:床单式 颜色分类:兰色;产品等级:一等品;风格:乡村田园;面料支数:40支;面料密度: 128x68;印花工艺: 活性印花;织造工艺: 其他
				String[] arr = properties.split(";");
				for (String string : arr) {
					String[] keyValues = string.split(":");
					if (keyValues.length == 2) {
						ProductPropertiesDTO pp = new ProductPropertiesDTO();
						pp.setName(keyValues[0]);
						pp.setValue(keyValues[1]);
						//pp.setProduct(p);
						pp.setSpecification(s);
						productPropertiesService.create(pp);
					}
				}
			}
			
			eventDispather.specificationChanged(productDTO.getId());
			
			
		}
	
		return okAndClose(new JsonResultDTO());
	}

	public static void main(String[] args) throws Exception {
		Logs.COMMON.debug(String.format("%04d", 0));

		/*Workbook book = WorkbookFactory.create(new FileInputStream(
				new File("/Users/kevin/Documents/1_ougong/B2B上传/B2B上传/布艺/江苏金太阳布业有限公司（金太阳）商城上传表+10%.xls")));

		// 获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2,3,....)
		Sheet sheet = book.getSheetAt(0);
		// 获取左上角的单元格
		int count = 0;
		Iterator<Row> iterable = sheet.rowIterator();
		iterable.next();
		while (iterable.hasNext()) {
			Row row = iterable.next();
			if (row.getCell(0) == null) {
				continue;
			}
			String name = row.getCell(0).getStringCellValue().trim();
			if (StringUtils.isBlank(name)) {
				continue;
			}
			String subTitle = row.getCell(1).getStringCellValue().trim();
			String unit = row.getCell(3).getStringCellValue().trim();
			String brand = row.getCell(4).getStringCellValue().trim();
			String properties = row.getCell(5).getStringCellValue().trim();
			// 规格编码
			String specCode = row.getCell(6).getStringCellValue().trim();
			String spec1 = row.getCell(7).getStringCellValue().trim();
			String spec2 = row.getCell(8).getStringCellValue().trim();
			double sellingPrice = 0;
			try {
				sellingPrice = row.getCell(9).getNumericCellValue();
			} catch (Exception e) {
				sellingPrice = Double.parseDouble(row.getCell(9).getStringCellValue().trim());
			}

			String stock = null;
			try {
				stock = row.getCell(13).getStringCellValue().trim();
			} catch (Exception e) {
				stock = "" + row.getCell(13).getNumericCellValue();
			}

			Logs.COMMON.debug(name);
		}*/
	}
}
